package com.yanggu.scala.chapater08.accompanyObject

object Demo02 {

  def main(args: Array[String]): Unit = {
    //这里可以使用伴生对象的名称例如Pig(参数1, 参数2)。直接得到实例化对象
    //会自动调用伴生对象的apply方法构建实例对象
    println(Pig("李四"))
  }

}

class Pig(var name: String = "王五") {

  Pig.test1()

  println(s"伴生对象的编号字段的值: ${Pig.number}")

  override def toString: String = s"小猪的名字是$name"

}

object Pig {

  val number = 0L

  def apply(name: String): Pig = new Pig(name)

  def apply(): Pig = new Pig()

  def test1(): Unit = {
    println("伴生对象Pig中的方法test1()被调用了。。。。")
  }

}